﻿<cfcomponent displayname="Install" hint="Install" extends="Controller" output="false">

	<cffunction name="init" access="public" hint="init" displayname="init">
		
		<cfscript>
			isInstalled = model("setting").getSetting("installed");
			
			// prevent from second installation process
			if (isInstalled) {
				t = flashInsert(error="Already installed");
				
				redirectTo(controller="Home");
			}
			
			return this;
			
		</cfscript>
		
	</cffunction> 
	
	<cffunction name="home" access="public" hint="install home" displayname="install home">
		
		<cfscript>
			
			user = model("user").new();
			company = model("company").new();
			
		</cfscript>
		
	</cffunction>
	
	<cffunction name="install" access="public" hint="installation process" displayname="install">
		
		
		<cfscript>
			// save admin user
			user = model("user").new();
			
			user.userName = params.user.username;
			user.userPassword = shaHash(params.user.password);
			user.isAdmin = "Y";
			user.userStatus = "A";
			user.crossCompany = "Y";
			
			user.save();
			
			if (user.hasErrors()) {
				renderPage(action="home");
			}
			/*
			// admin as dummy person
			person = model("person");
			
			person.firstName = params.username;
			person.userId = user.key();
			
			person.save();
			
			
			// save company
			company = model("company");
			
			company.companyName = params.company;
			company.address = params.address;
			company.phone = params.phone;
			company.fax = params.fax;
			
			company.save();
			
			// set installed flag to true
			setting = model("setting").setSetting("installed", "true");
			
			flashInsert(info="Install success");
			redirectTo(controller="Home");
			*/
		</cfscript>
		
	</cffunction>
	
</cfcomponent>